import { axiosInstance } from 'src/boot/axios'
import CommonConfig from 'src/assets/js/config'

const schemaUrl = CommonConfig.schemaUrl + '/v1'

/**
 * 获取客制化设置数据
 * normRevise 定额修正
 * passRate 合格率阀值
 * sendPrecision 派工精度类型 0: 小数 1：整数
 * smallStop 小停机
 * takePlaceStopMax 取放停机最大值
 * takePlaceStopMin 取放停机最小值
 */

export function getCustomerSet () {
  const url = schemaUrl + '/custom'

  return axiosInstance.get(url).then(resp => {
    return Promise.resolve(resp.data)
  })
}

/**
 * 编辑客制化设置数据
 * normRevise 定额修正
 * passRate 合格率阀值
 * sendPrecision 派工精度类型 0: 小数 1：整数
 * smallStop 小停机
 * takePlaceStopMax 取放停机最大值
 * takePlaceStopMin 取放停机最小值
 */

export function setCustomerSet (params) {
  const url = schemaUrl + '/custom_mode/custom'

  return axiosInstance.put(url, params).then(resp => {
    return Promise.resolve(resp.data)
  })
}

// 获取生产组织架构-树形选择器结构
export function getOrganize () {
  const newUrl = schemaUrl + '/workshop_auto_withdraws'

  return axiosInstance.get(newUrl).then((res) => {
    return Promise.resolve(res.data)
  })
}

// 获取生产组织架构-树形选择器结构
export function setAutoWithdraw (workshopId, isAuto) {
  let newUrl = `${schemaUrl}/workshops/${workshopId}/auto_withdraw:`
  isAuto && (newUrl += 'close')
  !isAuto && (newUrl += 'open')

  return axiosInstance.post(newUrl).then((res) => {
    return Promise.resolve(res)
  })
}
